import cv2

img=cv2.imread(r'C:\Users\Lenovo\Desktop\CV-Pictures\018.jpg')
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

t1,dst1=cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
t2,dst2=cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV)

cv2.imshow('img',img)
cv2.imshow('gray',gray)
cv2.imshow('dst1',dst1)
cv2.imshow('dst2',dst2)
cv2.waitKey(0)
cv2.destroyAllWindows()